package com.csi.bumblebee.controller;


import com.csi.bumblebee.domain.user.Resume;
import com.csi.bumblebee.domain.util.MyResult;
import com.csi.bumblebee.domain.util.StateCode;
import com.csi.bumblebee.service.ResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 韦典良
 * @author HUOJT
 */
@RestController
@RequestMapping("/resume")
public class ResumeController {

    @Autowired
    private ResumeService resumeService;

    /**
     * 修改简历信息
     */
    @PutMapping("/try/change")
    public MyResult<Integer> updateResume(@RequestBody Resume resume){

        int num = this.resumeService.updateResume(resume);

        if (num>0){
            return new MyResult<>(num, StateCode.UPDATE_SUCCESS,"更新简历信息成功！");
        }

        return new MyResult<>(num, StateCode.UPDATE_FAILURE,"更新简历信息失败！");

    }


    /**
     * 增加简历信息
     */
    @PostMapping("/try/path")
    public MyResult<Integer> addResume(@RequestBody Resume resume){

        int num = this.resumeService.addResume(resume);

        if (num>0){
            return new MyResult<>(num,StateCode.INSERT_SUCCESS,"增加简历信息成功！");
        }

        return new MyResult<>(num,StateCode.INSERT_FAILURE,"增加简历信息失败！");

    }

    /**
     * 变更简历的启用状态
     */
    @PutMapping("/invoke")
    public MyResult<Integer> updateResumeStatus(@RequestBody Resume resume){

        int num = this.resumeService.updateResumeStatus(resume);

        if (num>0){
            return new MyResult<>(num,StateCode.UPDATE_SUCCESS,"更新简历启用状态成功！");
        }

        return new MyResult<>(num,StateCode.UPDATE_SUCCESS,"更新简历启用状态失败！");

    }

    /**
     * 根据学生id获取学生的简历
     */
    @GetMapping("/single/{studentId}")
    public MyResult<Resume> findResume(@PathVariable String studentId){

        Resume resume = resumeService.findResume(studentId);

        if (resume != null){
            return new MyResult<>(resume,StateCode.FIND_SUCCESS,"查询成功！");
        }

        return new MyResult<>(StateCode.FIND_SUCCESS,"查询失败！");

    }


}
